package com.hhh.sun.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.joda.time.DateTime;
import org.springframework.stereotype.Component;

/**
 * 一个拦截器，在插入和更新数据时进行拦截
 */
@Component
public class FillHandler implements MetaObjectHandler {
    /**
     * 数据插入之前进行拦截
     * @param metaObject entity对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", DateTime.now().toDate());
        metaObject.setValue("updateTime",DateTime.now().toDate());
    }

    /**
     * 数据更新之前进行拦截
     * @param metaObject entity对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime",DateTime.now().toDate());
    }
}
